﻿/**
* @description  Class to test simple FLV playback.
*/
package test {
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.media.Video;
	import flash.net.NetStream;

	import com.moke.media.controllers.FLVController;
	import com.moke.media.events.MediaEvent;
	
	[SWF(width=550, height=400)]

	public class FLVQuickTest extends Sprite {

		private var _flvController:FLVController;
		
		/**
		* @description  Constructor.
		*/
		public function FLVQuickTest() {
			init();
		}
		
		/**
		* @description  Creates controller and display, then loads video.
		*/
		private function init():void {
			_flvController = new FLVController();
			_flvController.addEventListener(Event.INIT, mediaInit, false, 0, true);
			_flvController.addEventListener(MediaEvent.COMPLETE, mediaComplete, false, 0, true);
			_flvController.loadMedia("../assets/cyber_minotaur.flv");
			
			var pDisplay:Video = addChild(new Video()) as Video;
			pDisplay.x = 115;
			pDisplay.y = 80;
			pDisplay.width = 320;
			pDisplay.height = 240;
			pDisplay.attachNetStream(NetStream(_flvController.media));

			stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown, false, 0, true);
		}
		
		/**
		* @description  Event handler for when media starts.
		*
		* @param  pEvent  Event fired by MediaController.
		*/
		private function mediaInit(pEvent:Event):void {
			trace("FLV init");
		}

		/**
		* @description  Event handler for when media completes.
		*
		* @param  pEvent  Event fired by MediaController.
		*/
		private function mediaComplete(pEvent:MediaEvent):void {
			trace("FLV complete");
		}

		/**
		* @description  Event handler for when stage is clicked.
		*
		* @param  pEvent  Event fired by Mouse.
		*/
		private function mouseDown(pEvent:MouseEvent):void {
			_flvController.pauseMedia(!_flvController.paused);
		}

	}
	
}